//package com.ruoyi.framework.security.filter;
//
//import com.fasterxml.jackson.databind.ObjectMapper;
//import org.springframework.http.MediaType;
//import org.springframework.security.authentication.AuthenticationServiceException;
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.core.AuthenticationException;
//import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.util.HashMap;
//import java.util.Map;
//
//public class VueLoginAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
//
//    private static final String METHOD_POST = "POST";
//
//
//    @Override
//    public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
//        if (!METHOD_POST.equals(request.getMethod())) {
//            throw new AuthenticationServiceException(
//                    "Authentication method not supported: " + request.getMethod());
//        }
//        //支持Json登陆
//        if (request.getContentType().contains(MediaType.APPLICATION_JSON_VALUE) || request.getContentType().contains(MediaType.APPLICATION_JSON_UTF8_VALUE)) {
//            float initialCapacity = 2 / 0.75F + 1.0F;
//            Map<String, String> loginData = new HashMap<>((int) initialCapacity);
//            try {
//                loginData = new ObjectMapper().readValue(request.getInputStream(), Map.class);
//            } catch (IOException e) {
//            } finally {
//            }
//            String username = loginData.get(getUsernameParameter());
//            String password = loginData.get(getPasswordParameter());
//            if (username == null) {
//                username = "";
//            }
//            if (password == null) {
//                password = "";
//            }
//            username = username.trim();
//            UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(
//                    username, password);
//            setDetails(request, authRequest);
//            return this.getAuthenticationManager().authenticate(authRequest);
//        } else {
//            //POST登陆
//            return super.attemptAuthentication(request, response);
//        }
//
//    }
//
//
//}
//
//
